package mpcs.view
{
	import flash.events.Event;
	
	import flexlib.mdi.containers.MDIWindow;
	
	import mpcs.model.vo.GlobalVO;
	import mpcs.utils.ComponentManager;
	import mpcs.utils.MDIWindowPools;
	import mpcs.utils.MDIWindowType;
	import mpcs.view.components.StartPanel;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	public class StartPanelMediator extends Mediator {
		
		public static const NAME:String = "StartPanelMediator";
		
		public function StartPanelMediator( viewComponent:StartPanel ) {
			super(NAME, viewComponent);
		}
		
		override public function onRegister():void {
			startPanel.addEventListener( StartPanel.CLICK_LOCATION, onLocation );
			startPanel.addEventListener( StartPanel.CLICK_USERINFO, onUserinfo );
		}
		
		/**打开实时位置窗口请求**/
		private function onLocation( event:Event ):void {
			
			trace("请求实时位置窗口 ... ");
			
			if( ComponentManager.isopen_location ) {
				trace("恢复实时位置窗口 ... ");
				if(ComponentManager.locationMDIWindow == null)
					return;
				ComponentManager.locationMDIWindow.maximize();
				ComponentManager.locationMDIWindow.setFocus();
				return;
			}else{
				ComponentManager.isopen_location = true;
				var mapWin:MDIWindow = MDIWindowPools.getInstance().getMDIWindow( MDIWindowType.MAP_TYPE );
				mapWin.id = "mapMDI";
				mapWin.title = "实时位置";
				GlobalVO.mpcsApp.mainPanel.desktopPanel.mdiWindow.mdiCanvas.windowManager.add( mapWin );
				ComponentManager.locationMDIWindow = mapWin;
				trace("新建实时位置窗口 ... ");
			}
		}
		
		/**打开用户信息窗口请求**/
		private function onUserinfo( event:Event ):void {
			
			trace("请求用户信息窗口 ... ");
			
			if( ComponentManager.isopen_userinfo ) {
				trace("恢复用户信息窗口 ... ");
				if(ComponentManager.userinfoMDIWindow == null)
					return;
				ComponentManager.userinfoMDIWindow.maximize();
				ComponentManager.userinfoMDIWindow.setFocus();
				return;
			}else{
				ComponentManager.isopen_userinfo = true;
				var infoWin:MDIWindow = MDIWindowPools.getInstance().getMDIWindow( MDIWindowType.USERINFO_TYPE );
				infoWin.id = "userinfoMDI";
				infoWin.title = "个人信息";
				GlobalVO.mpcsApp.mainPanel.desktopPanel.mdiWindow.mdiCanvas.windowManager.add( infoWin );
				ComponentManager.userinfoMDIWindow = infoWin;
				trace("新建用户信息窗口 ... ");
			}
		}
		
		override public function listNotificationInterests():Array {
			return [];
		}
		
		override public function handleNotification( note:INotification ):void {
			
		}
		
		private function get startPanel ():StartPanel {
			return viewComponent as StartPanel;
		}
	}
}